<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组的push和pop方法</title>
</head>

<body>
    <script>
        var datas = [];
        console.log(datas.length);
        //push方法可一次性插入多个元素，元素之间用逗号隔开    
        datas.push('beijing');
        console.log(datas);
        // var dnt = datas.push('beijing');
        // console.log(dnt);
        datas.push('shanghai');
        console.log(datas);
        var dnt = datas.push('guangzhou', 'hangzhou');
        console.log(dnt);    //返回值：数组长度  4

        //pop方法：删除数组最后一个元素
        var ddn = datas.pop();
        console.log(ddn);  //返回值：该元素的值  hangzhou
        console.log(datas);

        //如果数组为空，则pop方法弹出undefined
        var empty = [];
        element = empty.pop();
        console.log(element);  //undefined
        console.log(empty);    //[]

        //shift:删除开头元素
        element = datas.shift();
        console.log(element);   //返回值：该元素的值
        console.log(datas);

        //unshift:在开头添加元素
        element = datas.unshift('changsha');
        console.log(element);   //返回值：数组长度
        console.log(datas);
    </script>
</body>

</html>